package com.ccepc.algmanage.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ccepc.algmanage.mapper.LinkedDeviceMapper;
import com.ccepc.algmanage.service.LinkedDeviceService;
import com.ccepc.algmanage.service.PlcConfigService;
import com.ccepc.demo.api.entity.IdentificationRecord;
import com.ccepc.demo.api.entity.LinkedDevice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 *
 *
 * @author pigx code generator
 * @date 2023-11-02 14:45:05
 */
@Service
@Slf4j
public class LinkedDeviceServiceImpl extends ServiceImpl<LinkedDeviceMapper, LinkedDevice> implements LinkedDeviceService {
    @Resource
    private PlcConfigService plcConfigService;

    @Override
    public Object sendMessage(LinkedDevice linkedDevice, IdentificationRecord identificationRecord) {
        log.info("联动记录处理");
        String[] linkedIds = linkedDevice.getLinkedIds().split(",");
        for (String linkedId : linkedIds) {
            log.info("发送请求");
            try {
                plcConfigService.changeStatus(linkedId, "true", false);
            } catch (Exception e) {
                log.error(e.getMessage());
            }
        }
        return "success";
    }
}
